export interface QueryMenuByRole {
  roleId: number
}

export class ResMenuByRole {
  id?: number
  name?: string
  check?: boolean
  children?: Array<ResMenuByRole>

  static getCheck(resMenuByRoles: Array<ResMenuByRole> | undefined): Array<number> {
    const checkedKeys: Array<number> = []
    if (resMenuByRoles === undefined) {
      return checkedKeys
    }
    resMenuByRoles.forEach((item: ResMenuByRole) => {
      if (item.check && item.id !== undefined) {
        checkedKeys.push(item.id)
      }
      checkedKeys.push(...ResMenuByRole.getCheck(item.children))
    })
    return checkedKeys
  }
}

export class SetMenuReq {
  roleId: number
  modules: Array<number>

  constructor(roleId: number, modules: Array<number>) {
    this.roleId = roleId
    this.modules = modules
  }
}
